<?php 

/**
* 评价控制器
*/
class CommentController extends CommonController{
	private $model;
	/**
	 * [__init 构造函数]
	 * @return [type] [description]
	 */
	public function __init(){
		parent::__init();
		$this->model=K("Comment");
		if (!isset($_SESSION['uid'])) {
            $this->success('未登录,请先登录',U('Login/index'));
        }
	}
	/**
	 * [index 首页动作]
	 * @return [type] [description]
	 */
	public function index(){
		 $olid = Q('get.olid',0,'intval');
		 $orderListData = K('OrderList')->get_one_data(array('olid'=>$olid));
		 $this->assign('orderListData',$orderListData);
		// 显示视图
		$this->dis('comment.html');
	}
	/**
	 * [add 增加动作]
	 */
	public function add(){
		if (!isset($_SESSION['uid'])) {
            echo 0;
            die();
        }
        // p($_POST);die();
        if(!IS_POST) $this->error('非法请求',__ROOT__);
        $olid =Q('post.olid',0,'intval');
        $gid = Q('post.gid',0,'intval');
		$data = array(
        		'star'    => Q('post.star',0,'intval')*2*10,
		        'gid'     => $gid,
		        'olid'    => $olid,
		        'content' => Q('post.content'),
		        'uid'     =>$_SESSION['uid'],
		        'uname'   => $_SESSION['u_username'],
		        'pic'     => $_SESSION['u_pic'],
        		);
        $this->model->add_data($data);
        $avg = $this->model->avg_data(array('gid'=>$gid),'star');
        $avg =intval($avg);
        $model =K('Goods');
        $cnum =$model->get_gids(array('gid'=>$gid),'cnum');
        $cnum =$cnum[0];
        $cnum =$cnum+1;
        $model->update_data(array('gid'=>$gid),array('rank'=>$avg,'cnum'=>$cnum));
        K('OrderList')->update_data(array('olid'=>$olid),array('is_comment'=>1));
        $this->success('评价成功',U('Menber/comment'));
	}
	/**
	 * [del 删除动作]
	 * @return [type] [description]
	 */
	public function del(){
		$gid = Q('get.gid',0,'intval');
		$uid =intval($_SESSION['uid']);
		$this->model->delete_data("gid=$gid And uid=$uid");
		$this->success('删除成功',U('Menber/store'));
	}
	
}
















 ?>